From 3005f1b844511a34865f3f60b61542a1ed13c03c Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Sun, 23 Dec 2012 21:58:20 +0100 Subject: [PATCH] broadway: disconnect in idle when needed This makes the ownership cleaner --- gdk/broadway/broadway-server.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/gdk/broadway/broadway-server.c b/gdk/broadway/broadway-server.c index abb750f857..2931d94853 100644 --- a/gdk/broadway/broadway-server.c +++ b/gdk/broadway/broadway-server.c @@ -20,11 +20,13 @@ typedef struct { GBufferedInputStream *in; guint32 last_seen_serial; GList *windows; + guint disconnect_idle; } BroadwayClient; static void client_free (BroadwayClient *client) { + g_assert (client->disconnect_idle == 0); clients = g_list_remove (clients, client); g_object_unref (client->connection); g_object_unref (client->in); @@ -34,11 +36,35 @@ client_free (BroadwayClient *client) static void client_disconnected (BroadwayClient *client) { + if (client->disconnect_idle != 0) + { + g_source_remove (client->disconnect_idle); + client->disconnect_idle = 0; + } + g_print ("client %d disconnected\n", client->id); + /* TODO: destroy client windows, also maybe do this in an idle, at least in some cases like on an i/o error */ + client_free (client); } +static gboolean +disconnect_idle_cb (BroadwayClient *client) +{ + client->disconnect_idle = 0; + client_disconnected (client); + return G_SOURCE_REMOVE; +} + +static void +client_disconnect_in_idle (BroadwayClient *client) +{ + if (client->disconnect_idle == 0) + client->disconnect_idle = + g_idle_add_full (G_PRIORITY_DEFAULT, (GSourceFunc)disconnect_idle_cb, client, NULL); +} + static void send_reply (BroadwayClient *client, BroadwayRequest *request, @@ -57,8 +83,7 @@ send_reply (BroadwayClient *client, if (!g_output_stream_write_all (output, reply, size, NULL, NULL, NULL)) { g_printerr ("can't write to client"); - client_disconnected (client); - /* TODO: Make sure we don't access client after this */ + client_disconnect_in_idle (client); } } -- 2.30.2